/*******************************************************************************
 * @file hal_i2c.c
 * @brief I2C Interface drivers
 *
 * @version 1.0.0
 *******************************************************************************
 * @license Refer License or other description Docs
 * @author  Felix
 ******************************************************************************/
#include "hal_i2c.h"
#include "utils/util.h"
#include "em_device.h"
#include "cpu/bsp_i2c.h"
#include "sensor/sensor.h"
#include "sensor/sht41.h"
#include "bsp.h"

/****
Local Functions
****/
struct sensor_func sfunc0 = {
    .flag = false,
    .delay = os_delay,
    .read = NULL,
    .write = NULL
};

static stc_gpio_cfg_t gpiocfg = {0};

/****
Global Functions
****/
bool Hal_I2C_SensorInit(void)
{
    BSP_I2C_TypeDef i2c = {0};

    bool success = true;

    i2c.idx         = 1;    /* I2C0 */
    i2c.baud        = 100;  //100K
    i2c.scl_port    = I2C1_SCL_PORT;
    i2c.scl_pin     = I2C1_SCL_PIN;
    i2c.sda_port    = I2C1_SDA_PORT;
    i2c.sda_pin     = I2C1_SDA_PIN;
    i2c.af          = I2C1_ALTERF;

    BSP_I2C_Init(&i2c);

    sfunc0.delay = os_delay;
    sfunc0.read = BSP_I2C_Read;
    sfunc0.write = BSP_I2C_Write;
    sfunc0.flag = true;
    sfunc0.idx = i2c.idx;

    success = sensor_init(&sfunc0);

    return success;
}

void Hal_I2C_SensorDeInit(void)
{

}
